package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.PreListApi;
import com.jjb.www.http.api.TeachPlanListApi;
import com.jjb.www.http.glide.GlideApp;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 岗前培训报名adapter
 */
public final class PreAdapter extends AppAdapter<PreListApi.Bean> {
    private LabelPreAdapter adapter;
    public PreAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvTime;
        private WrapRecyclerView mRvLabel;
        private ShapeTextView mTvTipsTime;
        private ShapeTextView mTvMoney;
        private ShapeImageView mImgMecHead;
        private ShapeTextView mTvMecName;



        private ViewHolder() {
            super(R.layout.item_pre);
            mTvTime = findViewById(R.id.tv_time);
            mTvTipsTime = findViewById(R.id.tv_tips_time);
            mTvMoney = findViewById(R.id.tv_money);
            mImgMecHead = findViewById(R.id.img_mec_head);
            mTvMecName = findViewById(R.id.tv_mec_name);
            mRvLabel = findViewById(R.id.rv_label);
            mRvLabel.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
            adapter = new LabelPreAdapter(getContext());
            mRvLabel.setAdapter(adapter);
        }

        @Override
        public void onBindView(int position) {
            PreListApi.Bean bean = getItem(position);
            adapter.setData(bean.getLabel());
            mTvTime.setText(bean.getClass_time());
            mTvTipsTime.setText(bean.getDay()+"天");
            mTvMecName.setText(bean.getMech_name());
            if (bean.getIs_show()==1){
                mTvMoney.setVisibility(View.INVISIBLE);
            }else {
                mTvMoney.setVisibility(View.VISIBLE);
                mTvMoney.setText("¥"+bean.getAndroid_money());
            }
            GlideApp.with(getContext())
                    .load(bean.getPhoto())
                    .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                    .into(mImgMecHead);
        }
    }
}